package com.faeple.log.service;

import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.faeple.log.dao.LogDao;
import com.faeple.user.entity.UserDto;

@Service
public class LogServiceImpl implements LogService {

	@Autowired
	LogDao dao;
	
	@Override
	public void recordLoginLog(UserDto userDto, String ip) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("ip", ip);
		map.put("member_idx", userDto.getIdx());
		map.put("member_name", userDto.getName());
		map.put("action", "login");
		dao.recordLoginLog(map);
	}

	@Override
	public void recordLogoutLog(UserDto userDto, String ip) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("ip", ip);
		if(userDto != null){
			map.put("member_idx", userDto.getIdx());
			map.put("member_name", userDto.getName());
			map.put("action", "logout");
		}else{
			map.put("member_idx", "0");
			map.put("member_name", "notSession");
			map.put("action", "logout");
		}
		dao.recordLogoutLog(map);
	}

}